*************************************************************************************************
* Documentation for Reproduction of
* Justice Has Served: US Supreme Court Justice Retirement Strategies. 2013.
* Justice System Journal. Volume 34(2): 208-227.
* L.J Zigerell
* Stata version 9
*************************************************************************************************
*************************************************************************************************
set more off
set mem 500m
* use "Zigerell 2013 Justice Has Served.dta", clear [This is the command to load the dataset]
* the dataset used was the merged version of the 2005 World Values Survey
*************************************************************************************************

set more off

drop if year < 1962



// Code political environments

gen favpole = 0
replace favpole = 1 if bailey <= 0 & presideo <= 0
replace favpole = 1 if bailey >= 0 & presideo >= 0

** Revised Byron White
replace favpole = 1 if justice == "White" & presdem == 1
replace favpole = 0 if justice == "White" & presdem == 0

** Revised Harry Blackmun
replace favpole = 0 if justice == "Blackmun" & year == 1973
replace favpole = 0 if justice == "Blackmun" & year == 1974
replace favpole = 0 if justice == "Blackmun" & year == 1975
replace favpole = 0 if justice == "Blackmun" & year == 1976
replace favpole = 1 if justice == "Blackmun" & year == 1977
replace favpole = 1 if justice == "Blackmun" & year == 1978
replace favpole = 1 if justice == "Blackmun" & year == 1979

tab favpole



// Code delay strategy

gen delay = 0
replace delay = 1 if favpole == 1 & year == 1969
replace delay = 1 if favpole == 1 & year == 1977
replace delay = 1 if favpole == 1 & year == 1981
replace delay = 1 if favpole == 1 & year == 1993
replace delay = 1 if favpole == 1 & year == 2001
replace delay = 1 if favpole == 1 & year == 2009

replace delay = 1 if favpole == 1 & year == 1970
replace delay = 1 if favpole == 1 & year == 1982
replace delay = 1 if favpole == 1 & year == 1994
replace delay = 1 if favpole == 1 & year == 1995
replace delay = 1 if favpole == 1 & year == 2010

replace delay = 0 if justice == "Burger" & year == 1970
replace delay = 0 if justice == "O'Connor" & year == 1982
replace delay = 0 if justice == "Ginsburg" & year == 1994
replace delay = 0 if justice == "Breyer" & year == 1995
replace delay = 0 if justice == "Ginsburg" & year == 1995
replace delay = 0 if justice == "Sotomayor" & year == 2010

tab delay



// Code hasten strategy

gen hasten = 0

replace hasten = 1 if favpole == 1 & (year == 1963 | year == 1964)
replace hasten = 1 if favpole == 1 & (year == 1967 | year == 1968)
replace hasten = 1 if favpole == 1 & (year == 1971 | year == 1972)
replace hasten = 1 if favpole == 1 & (year == 1975 | year == 1976)
replace hasten = 1 if favpole == 1 & (year == 1979 | year == 1980)
replace hasten = 1 if favpole == 1 & (year == 1983 | year == 1984)
replace hasten = 1 if favpole == 1 & (year == 1987 | year == 1988)
replace hasten = 1 if favpole == 1 & (year == 1991 | year == 1992)
replace hasten = 1 if favpole == 1 & (year == 1995 | year == 1996)
replace hasten = 1 if favpole == 1 & (year == 1999 | year == 2000)
replace hasten = 1 if favpole == 1 & (year == 2003 | year == 2004)
replace hasten = 1 if favpole == 1 & (year == 2007 | year == 2008)

tab hasten



// Code happenstance observations

gen happen = 0
replace happen = 1 if favpole == 1 & delay == 0 & hasten == 0
tab happen



// Code unstrategic observations

gen unstr = 0
replace unstr = 1 if favpole == 0
tab unstr



// Construct control variables

* gen d_birthdate = date(birthdate, "mdy")
* gen d_dec31 = date(dec31, "mdy")
* note: change the above lines to the next two lines if using State version 9

gen d_birthdate = date(birthdate, "MDY")
gen d_dec31 = date(dec31, "MDY")
gen age = (d_dec31 - d_birthdate)/365.2425
summ age
egen z_age = std(age)
summ z_age
pwcorr age z_age
gen age2 = age*age
summ age2
egen z_age2 = std(age2)
summ z_age2
pwcorr age2 z_age2

gen dissent = 100 - majpct
summ dissent
egen z_dissent = std(dissent)
summ z_dissent
gen dissent2 = dissent*dissent
egen z_dissent2 = std(dissent2)
summ z_dissent2


egen median = median(bailey), by(year)
gen ideox = abs(bailey - median)
summ ideox
egen z_ideox = std(ideox)
summ z_ideox

gen ideox_b = abs(bailey)
summ ideox_b
egen z_ideox_b = std(ideox_b)
summ z_ideox_b

gen ideox_b2 = abs(bailey)*abs(bailey)
summ ideox_b2
egen z_ideox_b2 = std(ideox_b2)
summ z_ideox_b2



// Eliminate duplicate opportunities

tab delay hasten
tab year if hasten == 1 & delay == 1
tab justice if hasten == 1 & delay == 1
replace delay = 1 if year == 1995 & justice == "Souter"
replace delay = 1 if year == 1995 & justice == "Stevens"
replace hasten = 0 if year == 1995 & justice == "Souter"
replace hasten = 0 if year == 1995 & justice == "Stevens"
tab delay hasten



// Summary statistical results (page 13)

tab retire delay
tab retire hasten
tab retire happen
tab retire if favpole==0


prtest retire, by(delay)
prtest retire, by(hasten)
prtest retire, by(happen)
prtest retire, by(favpole)

prtest retire if delay==1 | hasten == 1, by(delay)
prtest retire if delay==1 | happen == 1, by(delay)
prtest retire if delay==1 | favpole == 0, by(delay)

egen tenure_mean = mean(tenure)
gen tenure1 = 365.25*(tenure - tenure_mean)
gen tenure2 = tenure1^2
gen tenure3 = tenure1^3

egen year0 = min(year), by(justice)



// Table 1. Model 1. Logit

logit retire hasten happen unstr z_age pension pressure z_dissent z_ideox_b tenure1 tenure2 tenure3, robust cluster(justice)
estimates store A
fitstat
pre
precalc
estsimp logit retire hasten happen unstr z_age pension pressure z_dissent z_ideox_b tenure1 tenure2 tenure3, robust cluster(justice)
setx mean
setx hasten 0 happen 0 unstr 0
simqi
setx hasten 1 happen 0 unstr 0
simqi
setx hasten 0 happen 1 unstr 0
simqi
setx hasten 0 happen 0 unstr 1
simqi
drop b1-b12
collin delay hasten happen z_age pension pressure z_dissent z_ideox_b tenure1 tenure2 tenure3




// Table 1. Model 2. Cox

gen t0 = year - 1961
gen t1 = t0 + 1
stset t1, id(justice) failure(retire==1) time0(t0)
stdes

sts list

sts test delay, logrank
sts test delay, wilcoxon
sts graph, by(delay)

sts test hasten, logrank
sts graph, by(hasten)

sts test happen, logrank
sts graph, by(happen)

sts test pension, logrank
sts graph, by(pension)

sts test pressure, logrank
sts graph, by(pressure)


// Cox model: main model

stcox hasten happen unstr z_age pension pressure z_dissent z_ideox_b, robust cluster(justice) efron nolog
estimates store B

stcox hasten happen unstr z_age pension pressure z_dissent z_ideox_b, shared(justice) efron nolog
* does not converge

stcox delay hasten happen z_age pension pressure z_dissent z_ideox_b, robust cluster(justice) efron nolog


// Cox model: main model specification checks

stcox hasten happen unstr z_age pension pressure z_dissent z_ideox_b, robust cluster(justice) efron nolog scaledsch(sca*) schoenfeld(sch*) mgale(mg)
estat phtest, detail

estat phtest, plot(hasten)
estat phtest, plot(happen)
estat phtest, plot(unstr)
estat phtest, plot(z_age)
estat phtest, plot(pension)
estat phtest, plot(pressure)
estat phtest, plot(z_dissent)
estat phtest, plot(z_ideox_b)

drop sch* sca* mg*

collin hasten happen unstr z_age pension pressure z_dissent z_ideox_b



// Table 1. Model 3 check. Weibull w/o frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(weibull) robust cluster(justice) nolog



// Table 1. Model 3. Weibull w/ frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(weibull) frailty(gamma) shared(justice) nolog

* run w/o the next line first
estimates store C


// Table 1. Model 4 check. Exponential w/o frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(exponential) robust cluster(justice) nolog



// Table 1. Model 4. Exponential w/ frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(exponential) frailty(gamma) shared(justice) nolog
estimates store D



// Table 1. Model 5 check. Gompertz w/o frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(gompertz) robust cluster(justice) nolog



// Table 1. Model 5. Gompertz w/ frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(gompertz) frailty(gamma) shared(justice) nolog
estimates store E



// Table 1. Model 6 check. Log-normal w/o frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(lognormal) robust cluster(justice) nolog tr
estimates store F



// Table 1. Model 6. Log-normal w/ frailty

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(lognormal) frailty(gamma) shared(justice) nolog tr
estimates store G

* with delay but no unstr
streg delay hasten happen z_age pension pressure z_dissent z_ideox_b, distribution(lognormal) frailty(gamma) shared(justice) nolog tr

* with controls individually removed
streg hasten happen unstr pension pressure z_dissent z_ideox_b, distribution(lognormal) frailty(gamma) shared(justice) nolog tr
streg hasten happen unstr z_age pressure z_dissent z_ideox_b, distribution(lognormal) frailty(gamma) shared(justice) nolog tr
streg hasten happen unstr z_age pension z_dissent z_ideox_b, distribution(lognormal) frailty(gamma) shared(justice) nolog tr
streg hasten happen unstr z_age pension pressure z_ideox_b, distribution(lognormal) frailty(gamma) shared(justice) nolog tr
streg hasten happen unstr z_age pension pressure z_dissent, distribution(lognormal) frailty(gamma) shared(justice) nolog tr



// compare model fit

estimates table _all, stats(aic bic)


*************************************


// Table 1. Model 0 check. Gamma

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(gamma) frailty(gamma) nolog
* no convergence for frailty model



// Table 1. Model 0 check. Log-logistic

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(loglogistic) frailty(gamma) shared(justice) nolog
* no convergence for frailty model

streg hasten happen unstr z_age pension pressure z_dissent z_ideox_b, distribution(loglogistic) frailty(invgaussian) shared(justice) nolog
* no convergence for frailty model



// Model fit

quietly stcox hasten happen unstr z_age pension pressure z_dissent z_ideox_b, robust cluster(justice) efron
predict cs, csnell
stset cs, failure(retire==1)
sts generate H = na
line H cs cs, sort
drop cs H
stset t1, id(justice) failure(retire==1) time0(t0)



// Reverse double coding

tab delay hasten
tab year if hasten == 1 & delay == 1
tab justice if hasten == 1 & delay == 1
replace hasten = 1 if year == 1995 & justice == "Souter"
replace hasten = 1 if year == 1995 & justice == "Stevens"
replace delay = 0 if year == 1995 & justice == "Souter"
replace delay = 0 if year == 1995 & justice == "Stevens"
tab delay hasten
